Big Tree

The "Big Three" List Operations Overview:

In Scheme (and Scamper), there are three key higher-order list operations: map, apply, and reduce (also called fold). These operations are powerful tools for manipulating lists and allow for both repetition and parallelism.


1. map Function:

Example of map:

(map (lambda (x) (* x 2)) (list 1 2 3 4)) ; produces (2 4 6 8)

2. apply Function:

Example of apply:

(apply + (list 1 2 3 4 5)) ; produces 15

3. reduce (or fold) Function:

Example of reduce:

(reduce + (list 1 2 3 4)) ; produces 10

Combining Lists with Spaces:


Associativity and Efficiency:


4. filter Function:

Example of filter:

(filter odd? (list 1 2 3 4 5)) ; produces (1 3 5)

Using map with Multiple Lists:

Example:

(map + (list 1 2 3) (list 4 5 6)) ; produces (5 7 9)

Self-Check Questions:

  1. Check 1: Inconsistent Subtraction:

    • Find different results for the expression (4 - 1 - 6 - 3 - 2 - 10 - 8) using different orders of operation.
  2. Check 2: Pipelining (‡):

    • Extend an expression using map, filter, and reduce so that:
      • The list only contains names in "last, first" format with at least 13 characters.
      • The sum of the lengths of all these names is computed.